<?

class ELEMENTS	{

	function element( $type, $args, $callback = false )	{
	
		return array( 'type'=> $type, 'args'=> $args, 'callback'=> $callback );
	
	}
	
	function callback( $task, $type, $action, $params = array())	{
	
		$params['task'] = $task;
		$params['type'] = $type;
		$params['action'] = $action;
		
		return $params;
	}
}


class Button extends ELEMENTS	{

	function view( $value, $type = null, $action = null, $class = null ) {
	
		$args = array( 'value'=> $value );
		if( $class ) $args['class'] = $class;
	
		return self::element( 'button', $args, self::callback( 'view', $type, $action ));
	}

	function xhr( $value, $type = null, $action = null ) {
	
		return self::element( 'button', array( 'value'=> $value ), self::callback( 'xhr', $type, $action ));
	}
	
	function link( $value, $url ) {
	
		return self::element( 'button', array( 'value'=> $value, 'href'=> $url ));
	}

}

class Input extends ELEMENTS	{

	function text( $placeholder, $type, $action = null, $params = array()) {
	
		$params = array_merge( $params, array( 'type'=> 'text', 'placeholder'=> $placeholder ));
		return self::element( 'input', $params, self::callback( 'json', $type, $action ));
	}
	
	function update( $placeholder, $type, $params = array()) {
		
		return self::element( 'input', array( 'type'=> 'text', 'placeholder'=> $placeholder, 'class'=> 'fill' ), self::callback( 'json', $type, 'update', $params ));
	}
	
	function wordcount( $placeholder, $type, $params = array()) {
		
		return self::element( 'textarea', array( 'placeholder'=> $placeholder, 'class'=> 'fill' ), self::callback( 'json', $type, 'wordcount', $params ));
	}
}

class Text extends ELEMENTS	{

	function description( $value, $class = null ) {
	
		return self::element( 'text', array( 'value'=> $value, 'class'=> $class ));
	}

}

class UList extends ELEMENTS	{

	function unsorted( $list, $class = null, $height = null ) {
		
		return self::element( 'ulist', array( 'values'=> $list, 'class'=> $class, 'height' => $height ));
	}

}